package com.opmsys.mapper;

import com.opmsys.pojo.entity.Person;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface PersonMapper{
    /**
     * 新增一条人员信息
     * @param name
     * @param number
     * @param password
     * @param status
     * @param entry_date
     * @param head_img
     * @return
     */
    @Insert("insert into t_person(name,number,password,status,entry_date,head_img)values (#{name},#{number},#{password},#{status},#{entry_date},#{head_img})")
    public int addPerson(@Param("name") String name, @Param("number") Long number, @Param("password") String password, @Param("status") Integer status, @Param("entry_date") String entry_date, @Param("head_img") String head_img);

    /**
     *
     * @param number
     * @param password
     * @return
     */
    @Select("select * from t_person where number = #{number} and password = #{password} ")
    public Person selectPersonByNumAndPassword(@Param("number")Long number,@Param("password")String password);

    @Select("select * from t_person where number = #{number}")
    public List<Person> selectPersonByNum(@Param("number")Long number);


    
    @Select("select * from t_person where status = #{status} and number like CONCAT('%', #{number}, '%')")
    public List<Person> fuzzySelectPersonByNumber(@Param("status")Integer status,@Param("number") Long number);

    @Select("select * from t_person where status = #{status} and name like CONCAT('%', #{name}, '%')")
    public List<Person> fuzzySelectPersonByName(@Param("status")Integer status,@Param("name") String name);

    @Select("<script>" +
            "select * from t_person " +
            "<where>" +
            "<if test='status != null'>status = #{status} </if>" +
            "<if test='number != null'>and number like CONCAT('%', #{number}, '%') </if>" +
            "</where>" +
            "limit #{page_number}, #{page_size}" +
            "</script>")
    public List<Person> pagingFuzzySelectPersonByNumber(@Param("status")Integer status,@Param("number") Long number,@Param("page_number")Integer page_number,@Param("page_size")Integer page_size);


    @Select("<script>" +
            "select * from t_person " +
            "<where>" +
            "<if test='status != null'>status = #{status} </if>" +
            "<if test='name != null'>and name like CONCAT('%', #{name}, '%') </if>" +
            "</where>" +
            "limit #{page_number}, #{page_size}" +
            "</script>")
    public List<Person> pagingFuzzySelectPersonByName(@Param("status")Integer status,@Param("name") String name,@Param("page_number")Integer page_number,@Param("page_size")Integer page_size);
    @Update("update t_person set status = #{status} where number = #{number} ")
    public int changeStatus(@Param("number")Long number,@Param("status")Integer status);

    @Update("update t_person set password = #{password} where number = #{number} ")
    public int changePassword(@Param("number")Long number,@Param("password")String password);

    @Update("<script>" +
            "UPDATE t_person " +
            "<set>" +
            "<if test='id != null'> id = #{id}, </if>" +
            "<if test='name != null and name != \"\" '> name = #{name}, </if>" +
            "<if test='headImg != null and heahImg != \"\"'> head_img = #{headImg}, </if>" +
            "<if test='password != null and password != \"\" '> password = #{password}, </if>" +
            "<if test='status != null'> status = #{status}, </if>" +
            "<if test='entryDate != null and entryDate != \"\" '> entry_date = #{entryDate}, </if>" +
            "</set> " +
            "<where>" +
            "<if test='number != null'> number = #{number} </if>" +
            "</where> " +
            "</script>")
    public int update(@Param("name") String name,
                      @Param("headImg") String headImg,
                      @Param("number") Long number,
                      @Param("password") String password,
                      @Param("status") Integer status,
                      @Param("entryDate") String entryDate,
                      @Param("id") Integer id);

    @Select("select * from t_person where id = #{id}")
    Person selectById(Integer id);

    @Select("<script>" +
            "select * from t_person " +
            "<where>" +
            "<if test='status != null'>status = #{status} </if>" +
            "<if test='number != null'>and number like CONCAT('%', #{number}, '%') </if>" +
            "</where>" +
            "</script>")
    List<Person> pagingFuzzySelectPersonByNumberTotal(Integer status, long parseLong, Integer pageNum, Integer pageSize);

    @Select("<script>" +
            "select * from t_person " +
            "<where>" +
            "<if test='status != null'>status = #{status} </if>" +
            "<if test='name != null'>and name like CONCAT('%', #{name}, '%') </if>" +
            "</where>" +
            "</script>")
    List<Person> pagingFuzzySelectPersonByNameTotal(Integer status, String keyWords, Integer pageNum, Integer pageSize);


//    @Select("<script>" +
//            "SELECT * FROM t_test " +
//            "<where>" +
//            "<if test='wellId != null'> AND well_id = #{wellId} </if>" +
//            "<if test='personNumber != null'> AND person_number = #{personNumber} </if>" +
//            "<if test='pumpId != null'> AND pump_id = #{pumpId}  </if>" +
//            "<if test='estimatedDate != null'> AND  estimated_date like concat('%',#{estimatedDate},'%')  </if>" +
//            "<if test='actualDate != null'> AND actual_date like concat('%',#{actualDate},'%')  </if>" +
//            "</where> " +
//            "ORDER BY id " +
//            "LIMIT #{limit} OFFSET #{offset}"+
//            "</script>")
//    List<Test> getTestPageWithConditions(@Param("wellId") Integer wellId,
//                                         @Param("personNumber") Integer personNumber,
//                                         @Param("pumpId") Integer pumpId,
//                                         @Param("estimatedDate") String estimatedDate,
//                                         @Param("actualDate") String actualDate,
//                                         @Param("limit") Integer limit,
//                                         @Param("offset") Integer offset);

}
